﻿Public Class frmTimKH
    Dim connect As New connect()
    Dim flag As Integer
    Public Sub setflag(ByVal i As Integer)
        Me.flag = i
    End Sub
    Private Sub frmTimKH_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        cmbTim.Items.Insert(0, "Họ Tên")
        cmbTim.Items.Insert(1, "CMND")
        cmbTim.Items.Insert(2, "Số Điện Thoại")
        cmbTim.SelectedIndex = 0
    End Sub

    Private Sub btnTim_Click(sender As System.Object, e As System.EventArgs) Handles btnTim.Click
        Dim sql As String
        Select Case (cmbTim.SelectedIndex)
            Case 0
                sql = "select MAKH,HOTEN,NGAYSINH,CMND,DIENTHOAI from KHACHHANG where HOTEN like '%" + txtTuKhoa.Text + "%'"
            Case 1
                sql = "select MAKH,HOTEN,NGAYSINH,CMND,DIENTHOAI from KHACHHANG where CMND like '%" + txtTuKhoa.Text + "%'"
            Case 2
                sql = "select MAKH,HOTEN,NGAYSINH,CMND,DIENTHOAI from KHACHHANG where DIENTHOAI like '%" + txtTuKhoa.Text + "%'"
        End Select
        Dim dt As New DataTable
        dt = connect.GetData(sql)
        dgvKetQua.DataSource = dt
    End Sub

    Private Sub btnDong_Click(sender As System.Object, e As System.EventArgs) Handles btnDong.Click
        Me.Close()
    End Sub
    Private Sub btnChon_Click(sender As System.Object, e As System.EventArgs) Handles btnChon.Click
        If (dgvKetQua.CurrentRow.Cells.Count() > 0) Then
            Dim maKH As String = dgvKetQua.CurrentRow.Cells(0).Value.ToString().Trim()
            Dim tenKH As String = dgvKetQua.CurrentRow.Cells(1).Value.ToString().Trim()
            Dim CMND As String = dgvKetQua.CurrentRow.Cells(3).Value.ToString().Trim()
            Dim SDT As String = dgvKetQua.CurrentRow.Cells(4).Value.ToString().Trim()
            Select Case flag
                Case 1
                    frmQuanLy.UcTinDang1.ganKH(maKH, tenKH, CMND, SDT)
                Case 2
                    frmQuanLy.UcTimKiem1.ganTT(maKH, tenKH, CMND)
            End Select

        End If
        Me.Close()
    End Sub

    Private Sub txtTuKhoa_Click(sender As System.Object, e As System.EventArgs) Handles txtTuKhoa.Click
        txtTuKhoa.Text = ""
    End Sub

    Private Sub frmTimKH_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.KeyCode = Keys.Enter) Then
            btnChon.PerformClick()
        End If
    End Sub
End Class